package com.ylesb.aop;
/**
 * @title: CalculatorProxy
 * @projectName springdemo
 * @description: TODO
 * @author White
 * @site : [www.ylesb.com]
 * @date 2022/7/715:00
 */

import com.ylesb.aop.service.MyCalculatorImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @className    : CalculatorProxy
 * @description  : [描述说明该类的功能]  
 * @author       : [XuGuangchao]
 * @site         : [www.ylesb.com]
 * @version      : [v1.0]
 * @createTime   : [2022/7/7 15:00]
 * @updateUser   : [XuGuangchao]
 * @updateTime   : [2022/7/7 15:00]
 * @updateRemark : [描述说明本次修改内容] 
 */

public class CalculatorProxy {
    public static Object getInstance(MyCalculatorImpl myCalculator){
        return Proxy.newProxyInstance(myCalculator.getClass().getClassLoader(), myCalculator.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println(method.getName()+"方法开始执行");
                Object invoke = method.invoke(myCalculator, args);
                System.out.println(method.getName()+"方法结束执行");
                return invoke;
            }
        });
    }
}
